﻿namespace BM.Tools.WebControls.MForm.Controls.Helper
{
    using System.Web.UI;
    using System.Web.UI.WebControls;

    /// <summary>
    /// The title control of the button container
    /// </summary>
    public class ButtonContainerTitle : WebControl, ITextControl
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="ButtonContainerTitle"/> class. 
        /// </summary>
        public ButtonContainerTitle()
        {
            SetDefaults();
        }

        /// <summary>
        /// Gets or sets Text.
        /// </summary>
        /// <value>
        /// The text of the title.
        /// </value>
        public virtual string Text
        {
            get;
            set;
        }

        /// <summary>
        /// Gets TagKey.
        /// </summary>
        /// <value>
        /// The tag key - <see cref="HtmlTextWriterTag.Span" />.
        /// </value>
        protected override HtmlTextWriterTag TagKey
        {
            get
            {
                return HtmlTextWriterTag.Span;
            }
        }

        /// <summary>
        /// Adds a literal control with the text from the <see cref="Text" /> property
        /// </summary>
        protected override void CreateChildControls()
        {
            base.CreateChildControls();
            Controls.Add(new LiteralControl { Text = Text });
        }

        /// <summary>
        /// Renders the contents inside a <see cref="HtmlTextWriterTag.B" /> tags
        /// </summary>
        /// <param name="writer">
        /// The writer.
        /// </param>
        protected override void RenderContents(HtmlTextWriter writer)
        {
            writer.RenderBeginTag(HtmlTextWriterTag.B);
            base.RenderContents(writer);
            writer.RenderEndTag();
        }
        
        private void SetDefaults()
        {
            CssClass = "SubMenu";
        }
    }
}